<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<link rel="stylesheet" href="./temp/layui/css/layui.css">
	<script src="./temp/layui/layui.js"></script>
</head>
<body>
<?php if(isset($_SESSION['username'])){ ?>
<ul class="layui-nav" lay-filter="">
	<li class="layui-nav-item"><a href="">留言板</a></li>
	<div style="float: right">
		<li class="layui-nav-item"><a href="./login.php"><?php echo $_SESSION['username']?></a></li>
		<li class="layui-nav-item"><a href="./loginout.php">退出</a></li>
	</div>
</ul>
<?php }else{ ?>
<ul class="layui-nav" lay-filter="">
	<li class="layui-nav-item"><a href="">最新活动</a></li>
	<li class="layui-nav-item layui-this"><a href="">产品</a></li>
	<li class="layui-nav-item"><a href="">大数据</a></li>
	<li class="layui-nav-item">
		<a href="javascript:;">解决方案</a>
		<dl class="layui-nav-child"> <!-- 二级菜单 -->
			<dd><a href="">移动模块</a></dd>
			<dd><a href="">后台模版</a></dd>
			<dd><a href="">电商平台</a></dd>
		</dl>
	</li>
	<li class="layui-nav-item"><a href="">社区</a></li>
	<div style="float: right">
		<li class="layui-nav-item"><a href="./login.php">登陆</a></li>
		<li class="layui-nav-item"><a href="./reg.php">注册</a></li>
	</div>
</ul>
<?php } ?>
<div style="padding: 20px; background-color: #F2F2F2;">
	<div class="layui-row layui-col-space15">
		<?php foreach ($res as $k => $row): ?>
		<div class="layui-col-md4">
			<div class="layui-card">
				<div class="layui-card-header"><?php echo $row['username']?>
					<button style="float: right;margin-top: 5px;margin-left: 10px;
" class="layui-btn layui-btn-sm layui-btn-danger del" card_id="<?php echo $row['card_id'] ?>">删除
					</button>
					<a href="./edit.php?card_id=<?php echo $row['card_id'] ?>">
						<button style="float: right;margin-top: 5px;
" class="layui-btn layui-btn-sm layui-btn-warm edit">修改
						</button>
					</a>
				</div>
				<div class="layui-card-body">
					<?php echo $row['content']?>
					<span style="float: right;"><?php echo $row['create_time'] ?></span>
				</div>
			</div>
		</div>
		<?php endforeach ?>
	</div>
</div>
<div class="layui-form-item layui-form-text" style="margin-top: 100px">
	<label class="layui-form-label">文本域</label>
	<div class="layui-input-block">
		<textarea name="content" style="width: 500px;" placeholder="请输入内容" class="layui-textarea"></textarea>
		<button style="margin-top: 20px" id="issue" class="layui-btn">发布</button>
	</div>
</div>
<script>

    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;

        $('.edit').click(function () {
            id = $(this).attr('card_id');
            $.post("./edit.php", {card_id: id}, function (res, textStatus, xhr) {
                if (res.code == 0) {
                    layer.alert(res.msg, {icon: 6}, function () {
                        location.href = ('./temp/edit.html' + '?card_id' + '=' + id);
                    });
                } else {
                    layer.msg(res.msg, {icon: 9}, function () {
                    });
                }
            }, 'json');
        })

        $('.del').click(function () {
            card_id = $(this).attr('card_id');
            $.post("./del.php", {card_id: card_id}, function (res, textStatus, xhr) {
                if (res.code == 0) {
                    layer.alert(res.msg, {icon: 6}, function () {
                        location.reload();
                    });
                } else {
                    $('#code').click();
                    layer.msg(res.msg, {icon: 9}, function () {
                    });
                }
            }, 'json');
        })
        $('#issue').click(function () {
            content = $(this).siblings().val();
            $.post("./addContent.php", {content: content}, function (res, textStatus, xhr) {
                if (res.code == 0) {
                    layer.msg(res.msg, {icon: 6}, function () {
                        location.reload();
                    });
                } else {
                    $('#code').click();
                    layer.msg(res.msg, {icon: 9}, function () {
                    });
                }
            }, 'json');

        })

        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
</script>
</body>
</html>